package de.baumann.browser.present

import de.baumann.browser.R
import de.baumann.browser.api.OdinObserver
import de.baumann.browser.api.net.vo.CanCreatePool
import de.baumann.browser.base.BasePresenter
import de.baumann.browser.iview.ICanCreatePoolView
import de.baumann.browser.model.PoolModel

open class CanCreatePoolPresenter<N : ICanCreatePoolView> : BasePresenter<N>() {
    fun canCreatePool() {
        PoolModel().canCreatePool()
                .subscribe(object : OdinObserver<CanCreatePool>() {
                    override fun onSuccess(data: CanCreatePool?) {
                        if (data == null || view == null) {
                            return
                        }
                        when (data.can) {
                            0 ->
                                view.onError(R.string.Processing_please_be_patient)
                            1 ->
                                view.onError(R.string.cannot_be_reapplied)
                            2, 4 ->
                                view.canCreatePool()
                            -1 ->
                                view.onError(R.string.cannot_apply_for_a_mining_pool)
                        }
                    }
                })
    }
}